package com.example.itemtouchhelper

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.itemtouchhelper.entity.Bean

/**
 * @author by liliang on 2020/6/2 1:38 PM
 */
class CardAdapter(private var contentList: MutableList<Bean>, private var context: Context) :
    RecyclerView.Adapter<CardAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var textView: TextView = view.findViewById(R.id.tv)
        var linearLayout: LinearLayout = view.findViewById(R.id.linearLayout)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view =
            LayoutInflater.from(context).inflate(R.layout.item_card_recycler_view, parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount() = contentList.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.textView.text = contentList[position].name.plus("/").plus(itemCount)
        holder.linearLayout.setBackgroundColor(contentList[position].color)
    }
}